package com.kotlin.flong.flow

import kotlinx.coroutines.flow.asFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.reduce
import kotlinx.coroutines.runBlocking

/**
 * @Author:liangjl
 * @Date: 2020/7/10-21:49
 * @Eamil:jilongliang@sina.com
 * @Description:
 * 1、终止操作(Terminal Optional)
 * 2、Flow的终止操作都是挂起函数，终止操作才会真正开始流的收集
 * 3、toList与toSet
 * 4、获取一个元素
 * 5、reduce
 */

fun main() = runBlocking {

    var result = (1..4).asFlow().map { it * it }
        .reduce { a, b -> a + b }

    println(result)

}